let a1 = [1];
let a2 = ['1'];

let b1 = [1, 2];
let b2 = [1, [2]];

let c1 = [1, 2, 3, 4];
let c2 = [1, 2, 3, 4];

let d1 = ['a', ['b', ['c', 'd']]];
let d2 = ['a', ['b', ['c', 'd']]];
Array.prototype.equals = function(array1, array2) {
    if (!Array.isArray(array1) || !Array.isArray(array2) || array1.length != array2.length) {
        return false;
    }
    for (let i = 0; i < array1.length; i++) {
        if (Array.isArray(array1[i]) && Array.isArray(array2[i])) {
            if (!Array.prototype.equals(array1[i], array2[i])) return false;
        } else if (array1[i] !== array2[i]) {
            return false;
        }
    }
    return true;
}
console.log(Array.prototype.equals(a1, a2));
console.log(Array.prototype.equals(b1, b2));
console.log(Array.prototype.equals(c1, c2));
console.log(Array.prototype.equals(d1, d2));